#ifndef CONNECTION_H
#define CONNECTION_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>

static bool createConnection()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("my.db");
    if (!db.open())
    {
        qDebug("open my.db false!");
        return false;
    }

    QSqlQuery query;
    // 图片库
    query.exec(QString("create table if not exists myfiles "
                       "( path varchar not null primary key, "
                       "name varchar, isDelete int)"));
    // 参数设置库
    query.exec(QString("create table if not exists parasetting "
                       "( name varchar not null primary key, "
                       "time varchar, timeunit varchar, "
                       "shuffle boolean, start boolean, auto boolean)"));
    query.exec(QString("insert into parasetting values "
                       "('setting', '10', '秒', 1, 1, 1)"));
    return true;
}

#endif // CONNECTION_H
